/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.smart.hawk.utilities;

import java.awt.Component;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 * Clase que hereda el renderer de la tabla con el fin de poder montar
 * diferentes tipos de JComponent en ella
 *
 * @author Andres Escobar
 */
public class HawkCellRedererMgr extends DefaultTableCellRenderer {

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

        if (value instanceof JLabel) {
            JLabel label = (JLabel) value;
            label.setOpaque(true);
            fillColor(table, label, isSelected);
            label.repaint();
            return label;
        } else if (value instanceof JButton) {
            JButton button = (JButton) value;
            button.setOpaque(true);
            fillColor(table, button, isSelected);
            button.repaint();
            return button;
        } else {
            return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        }

    }

    /**
     * Fill color component
     *
     * @param t
     * @param l
     * @param isSelected
     */
    public void fillColor(JTable t, JComponent l, boolean isSelected) {
        if (isSelected) {
            l.setBackground(t.getSelectionBackground());
            l.setForeground(t.getSelectionForeground());
        } else {
            l.setBackground(t.getBackground());
            l.setForeground(t.getForeground());
        }
    }
}
